{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Pandas 修改列名和行名\n",
    "\n",
    "本教程详细介绍如何在 Pandas 中修改 DataFrame 的列名和行名（索引）。\n",
    "\n",
    "## 目录\n",
    "1. 直接赋值修改列名\n",
    "2. 直接赋值修改行名\n",
    "3. 使用 rename() 方法\n",
    "4. 使用 set_axis() 方法\n",
    "5. 列名清理技巧\n",
    "6. 最佳实践"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 导入库\n",
    "\n",
    "首先导入必要的库。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "pd.set_option('display.max_columns', None)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 直接赋值修改列名\n",
    "\n",
    "### 方法说明\n",
    "\n",
    "直接给 `df.columns` 属性赋值是最简单直接的方法。\n",
    "\n",
    "**语法:**\n",
    "```python\n",
    "df.columns = [新列名列表]\n",
    "```\n",
    "\n",
    "**参数:**\n",
    "- 必须提供与现有列数相同数量的列名\n",
    "\n",
    "**特点:**\n",
    "- ✅ 简单直接\n",
    "- ✅ 速度最快\n",
    "- ❌ 必须提供所有列名\n",
    "- ❌ 直接修改原 DataFrame（不可撤销）\n",
    "\n",
    "**适用场景:** 需要一次性替换所有列名时"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例1: 创建示例数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame({\n",
    "    'A': [1, 2, 3, 4],\n",
    "    'B': [5, 6, 7, 8],\n",
    "    'C': [9, 10, 11, 12]\n",
    "})\n",
    "\n",
    "print(\"原始 DataFrame:\")\n",
    "print(df)\n",
    "print(f\"\\n原始列名: {df.columns.tolist()}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例2: 完全替换所有列名\n",
    "\n",
    "将所有列名从 A, B, C 改为中文列名。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_copy = df.copy()\n",
    "df_copy.columns = ['列1', '列2', '列3']\n",
    "\n",
    "print(\"修改后的 DataFrame:\")\n",
    "print(df_copy)\n",
    "print(f\"\\n新列名: {df_copy.columns.tolist()}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例3: 注意事项 - 列名数量必须匹配\n",
    "\n",
    "⚠️ 如果提供的列名数量与实际列数不匹配，会抛出 `ValueError`。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    df_copy.columns = ['列1', '列2']  # 只提供2个列名，但有3列\n",
    "except ValueError as e:\n",
    "    print(f\"错误: {e}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 直接赋值修改行名（索引）\n",
    "\n",
    "### 方法说明\n",
    "\n",
    "类似地，可以直接修改 `df.index` 属性来更改行名。\n",
    "\n",
    "**语法:**\n",
    "```python\n",
    "df.index = [新索引列表]\n",
    "```\n",
    "\n",
    "**特点:**\n",
    "- 必须提供与现有行数相同数量的索引\n",
    "- 可以使用字符串、数字或日期等作为索引\n",
    "- 直接修改原 DataFrame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例1: 创建示例数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame({\n",
    "    '姓名': ['张三', '李四', '王五', '赵六'],\n",
    "    '年龄': [25, 30, 35, 40],\n",
    "    '城市': ['北京', '上海', '广州', '深圳']\n",
    "})\n",
    "\n",
    "print(\"原始 DataFrame:\")\n",
    "print(df)\n",
    "print(f\"\\n原始索引: {df.index.tolist()}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例2: 使用自定义字符串索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_copy = df.copy()\n",
    "df_copy.index = ['员工1', '员工2', '员工3', '员工4']\n",
    "\n",
    "print(\"修改索引后:\")\n",
    "print(df_copy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例3: 使用数字索引（从指定数字开始）\n",
    "\n",
    "默认索引从 0 开始，可以自定义起始数字。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_copy = df.copy()\n",
    "df_copy.index = range(1, 5)  # 从1开始\n",
    "\n",
    "print(\"使用数字索引（从1开始）:\")\n",
    "print(df_copy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例4: 重置索引为默认值\n",
    "\n",
    "使用 `reset_index()` 方法可以将索引重置为默认的 0, 1, 2...\n",
    "\n",
    "**参数:**\n",
    "- `drop=True`: 丢弃原索引，不作为新列\n",
    "- `drop=False`: 将原索引作为新列保留"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_copy = df.copy()\n",
    "df_copy.index = ['A', 'B', 'C', 'D']\n",
    "print(\"修改后的索引:\")\n",
    "print(df_copy)\n",
    "\n",
    "# 重置为默认索引\n",
    "df_reset = df_copy.reset_index(drop=True)\n",
    "print(\"\\n重置索引后:\")\n",
    "print(df_reset)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 使用 rename() 方法\n",
    "\n",
    "### 方法说明\n",
    "\n",
    "`rename()` 方法是最灵活的重命名方式，可以选择性地重命名特定的列或行。\n",
    "\n",
    "**语法:**\n",
    "```python\n",
    "df.rename(columns=映射, index=映射, inplace=False)\n",
    "```\n",
    "\n",
    "**参数:**\n",
    "- `columns`: 字典或函数，用于重命名列\n",
    "- `index`: 字典或函数，用于重命名行\n",
    "- `inplace`: 是否直接修改原 DataFrame（默认 False）\n",
    "- `errors`: 'raise' 或 'ignore'，处理不存在的标签\n",
    "\n",
    "**特点:**\n",
    "- ✅ 可以选择性重命名部分列/行\n",
    "- ✅ 支持字典和函数两种方式\n",
    "- ✅ 默认返回新 DataFrame，不修改原数据\n",
    "- ✅ 支持链式调用\n",
    "\n",
    "**适用场景:** 只需要重命名部分列或行时"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例1: 创建示例数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame({\n",
    "    'name': ['Alice', 'Bob', 'Charlie'],\n",
    "    'age': [25, 30, 35],\n",
    "    'city': ['NYC', 'LA', 'SF']\n",
    "}, index=['a', 'b', 'c'])\n",
    "\n",
    "print(\"原始 DataFrame:\")\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例2: 使用字典重命名特定列\n",
    "\n",
    "只重命名 name 和 age 列，city 列保持不变。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_renamed = df.rename(columns={'name': '姓名', 'age': '年龄'})\n",
    "\n",
    "print(\"重命名部分列:\")\n",
    "print(df_renamed)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例3: 使用字典重命名特定行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_renamed = df.rename(index={'a': '第一行', 'b': '第二行'})\n",
    "\n",
    "print(\"重命名部分行:\")\n",
    "print(df_renamed)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例4: 同时重命名列和行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_renamed = df.rename(\n",
    "    columns={'name': '姓名', 'age': '年龄', 'city': '城市'},\n",
    "    index={'a': '行1', 'b': '行2', 'c': '行3'}\n",
    ")\n",
    "\n",
    "print(\"同时重命名列和行:\")\n",
    "print(df_renamed)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例5: 使用函数批量修改\n",
    "\n",
    "将所有列名转换为大写。\n",
    "\n",
    "**常用函数:**\n",
    "- `str.upper`: 转大写\n",
    "- `str.lower`: 转小写\n",
    "- `str.capitalize`: 首字母大写\n",
    "- `str.strip`: 去除空格"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_renamed = df.rename(columns=str.upper)\n",
    "\n",
    "print(\"列名转大写:\")\n",
    "print(df_renamed)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例6: 使用 lambda 函数\n",
    "\n",
    "在所有列名前添加前缀 `col_`。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_renamed = df.rename(columns=lambda x: f'col_{x}')\n",
    "\n",
    "print(\"添加列名前缀:\")\n",
    "print(df_renamed)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例7: inplace 参数\n",
    "\n",
    "**注意:** 使用 `inplace=True` 会直接修改原 DataFrame，一般不推荐使用。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_copy = df.copy()\n",
    "df_copy.rename(columns={'name': '姓名'}, inplace=True)\n",
    "\n",
    "print(\"使用 inplace=True:\")\n",
    "print(df_copy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. 使用 set_axis() 方法\n",
    "\n",
    "### 方法说明\n",
    "\n",
    "`set_axis()` 方法可以设置新的轴标签（列名或行名）。\n",
    "\n",
    "**语法:**\n",
    "```python\n",
    "df.set_axis(labels, axis=0, inplace=False)\n",
    "```\n",
    "\n",
    "**参数:**\n",
    "- `labels`: 新的标签列表\n",
    "- `axis`: 0/'index' 表示行，1/'columns' 表示列\n",
    "- `inplace`: 是否直接修改原 DataFrame\n",
    "\n",
    "**特点:**\n",
    "- 必须提供完整的标签列表\n",
    "- 可以同时设置行和列\n",
    "- 返回新 DataFrame（除非 inplace=True）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例1: 创建示例数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame({\n",
    "    'A': [1, 2, 3],\n",
    "    'B': [4, 5, 6],\n",
    "    'C': [7, 8, 9]\n",
    "})\n",
    "\n",
    "print(\"原始 DataFrame:\")\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例2: 修改列名\n",
    "\n",
    "使用 `axis=1` 或 `axis='columns'` 修改列名。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_new = df.set_axis(['X', 'Y', 'Z'], axis=1)\n",
    "\n",
    "print(\"修改列名:\")\n",
    "print(df_new)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例3: 修改行名\n",
    "\n",
    "使用 `axis=0` 或 `axis='index'` 修改行名。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_new = df.set_axis(['row1', 'row2', 'row3'], axis=0)\n",
    "\n",
    "print(\"修改行名:\")\n",
    "print(df_new)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5. 列名清理技巧\n",
    "\n",
    "实际数据中，列名常常不规范，需要进行清理。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例1: 创建不规范的列名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame({\n",
    "    ' Name ': ['Alice', 'Bob'],\n",
    "    'AGE': [25, 30],\n",
    "    'City Name': ['NYC', 'LA'],\n",
    "    'Salary($)': [50000, 60000]\n",
    "})\n",
    "\n",
    "print(\"原始 DataFrame（列名不规范）:\")\n",
    "print(df)\n",
    "print(f\"列名: {df.columns.tolist()}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例2: 去除列名首尾空格\n",
    "\n",
    "使用 `str.strip()` 方法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_clean = df.rename(columns=lambda x: x.strip())\n",
    "\n",
    "print(\"去除空格后:\")\n",
    "print(df_clean.columns.tolist())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例3: 将列名转换为小写\n",
    "\n",
    "统一使用小写可以避免大小写混淆。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_lower = df.rename(columns=str.lower)\n",
    "\n",
    "print(\"转换为小写:\")\n",
    "print(df_lower.columns.tolist())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例4: 替换空格为下划线\n",
    "\n",
    "空格在代码中不方便使用，建议替换为下划线。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_underscore = df.rename(columns=lambda x: x.strip().replace(' ', '_'))\n",
    "\n",
    "print(\"空格替换为下划线:\")\n",
    "print(df_underscore.columns.tolist())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例5: 组合多个操作（完整清理）\n",
    "\n",
    "创建一个函数，组合多个清理操作。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def clean_column_name(col):\n",
    "    \"\"\"清理列名：去空格、转小写、替换特殊字符\"\"\"\n",
    "    col = col.strip()  # 去除首尾空格\n",
    "    col = col.lower()  # 转小写\n",
    "    col = col.replace(' ', '_')  # 空格替换为下划线\n",
    "    col = col.replace('(', '').replace(')', '')  # 去除括号\n",
    "    col = col.replace('$', 'usd')  # 替换特殊符号\n",
    "    return col\n",
    "\n",
    "df_clean = df.rename(columns=clean_column_name)\n",
    "\n",
    "print(\"完全清理后的列名:\")\n",
    "print(df_clean.columns.tolist())\n",
    "print(\"\\nDataFrame:\")\n",
    "print(df_clean)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例6: 使用 str 访问器批量修改\n",
    "\n",
    "Pandas 的 `str` 访问器可以链式调用多个字符串方法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_copy = df.copy()\n",
    "df_copy.columns = df_copy.columns.str.strip().str.lower().str.replace(' ', '_')\n",
    "\n",
    "print(\"使用 str 访问器:\")\n",
    "print(df_copy.columns.tolist())\n",
    "print(df_copy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 示例7: 添加前缀或后缀\n",
    "\n",
    "使用 `add_prefix()` 和 `add_suffix()` 方法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_test = pd.DataFrame({\n",
    "    'A': [1, 2],\n",
    "    'B': [3, 4],\n",
    "    'C': [5, 6]\n",
    "})\n",
    "\n",
    "# 添加前缀\n",
    "df_prefix = df_test.add_prefix('col_')\n",
    "print(\"添加前缀:\")\n",
    "print(df_prefix)\n",
    "\n",
    "# 添加后缀\n",
    "df_suffix = df_test.add_suffix('_data')\n",
    "print(\"\\n添加后缀:\")\n",
    "print(df_suffix)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6. 最佳实践\n",
    "\n",
    "关于修改列名和行名的建议。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 实践1: 避免使用 inplace\n",
    "\n",
    "**原因:**\n",
    "- 不可撤销\n",
    "- 难以调试\n",
    "- 不符合函数式编程理念\n",
    "\n",
    "**推荐做法:** 创建新对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})\n",
    "\n",
    "# ❌ 不推荐\n",
    "# df.rename(columns={'A': 'X'}, inplace=True)\n",
    "\n",
    "# ✅ 推荐\n",
    "df_new = df.rename(columns={'A': 'X'})\n",
    "\n",
    "print(\"原始 DataFrame 保持不变:\")\n",
    "print(df)\n",
    "print(\"\\n新 DataFrame:\")\n",
    "print(df_new)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 实践2: 列名规范化\n",
    "\n",
    "**好的列名特征:**\n",
    "- 小写字母\n",
    "- 使用下划线分隔单词\n",
    "- 避免特殊字符\n",
    "- 简洁明了\n",
    "- 有意义"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 不好的列名\n",
    "bad_df = pd.DataFrame({\n",
    "    'User Name': [1, 2],\n",
    "    'AGE(years)': [25, 30],\n",
    "    'Salary ($)': [50000, 60000]\n",
    "})\n",
    "\n",
    "# 规范化\n",
    "good_df = bad_df.rename(columns={\n",
    "    'User Name': 'user_name',\n",
    "    'AGE(years)': 'age_years',\n",
    "    'Salary ($)': 'salary_usd'\n",
    "})\n",
    "\n",
    "print(\"规范化前:\")\n",
    "print(bad_df.columns.tolist())\n",
    "print(\"\\n规范化后:\")\n",
    "print(good_df.columns.tolist())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 实践3: 检查重复列名\n",
    "\n",
    "重复列名会导致数据访问问题。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame([[1, 2, 3]], columns=['A', 'B', 'A'])\n",
    "\n",
    "print(\"DataFrame with duplicate columns:\")\n",
    "print(df)\n",
    "print(f\"\\n列名: {df.columns.tolist()}\")\n",
    "print(f\"是否有重复: {df.columns.duplicated().any()}\")\n",
    "print(f\"重复的列名: {df.columns[df.columns.duplicated()].tolist()}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 实践4: 使用有意义的索引\n",
    "\n",
    "使用有意义的索引可以提高数据可读性。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 示例：使用日期作为索引\n",
    "dates = pd.date_range('2024-01-01', periods=5)\n",
    "df = pd.DataFrame({\n",
    "    'sales': [100, 150, 120, 180, 200],\n",
    "    'profit': [20, 30, 25, 35, 40]\n",
    "}, index=dates)\n",
    "\n",
    "print(\"使用日期索引:\")\n",
    "print(df)\n",
    "print(f\"\\n索引类型: {type(df.index)}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 总结\n",
    "\n",
    "### 修改列名的方法对比\n",
    "\n",
    "| 方法 | 适用场景 | 优点 | 缺点 |\n",
    "|------|---------|------|------|\n",
    "| `df.columns = [...]` | 替换所有列名 | 简单直接、速度快 | 必须提供所有列名 |\n",
    "| `df.rename(columns={...})` | 选择性重命名 | 灵活、可部分修改 | 需要字典映射 |\n",
    "| `df.set_axis([...])` | 设置新轴标签 | 可同时设置列和行 | 必须提供完整列表 |\n",
    "| `df.add_prefix()/add_suffix()` | 批量添加前后缀 | 快速批量操作 | 只能添加前后缀 |\n",
    "\n",
    "### 关键要点\n",
    "\n",
    "1. **直接赋值** 适合完全替换所有列名或行名\n",
    "2. **rename()** 最灵活，可以选择性修改，支持函数和字典\n",
    "3. **set_axis()** 可以同时设置行和列的标签\n",
    "4. **列名规范化** 是数据清洗的重要步骤\n",
    "5. **避免重复列名** 会导致数据访问问题\n",
    "6. **使用有意义的索引** 可以提高数据可读性和操作效率\n",
    "7. **避免使用 inplace** 保持数据不可变性"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
